<?php


namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Api\BaseController;
use App\logic\ReservationLogic;
use App\Models\hospitalInformation;
use Illuminate\Http\Request;

/**
 * Class Reservation
 * @package App\Http\Controllers\Api\v1
 * name:王金玉
 * QQ:2162620371
 */
class ReservationController extends BaseController
{
    /**
     * 医院列表展示
     */
    public function PackageList(){
        try {
            $hospital=ReservationLogic::hospitalList();
            return $this->witejson(0,$hospital,'医院展示成功');
        }catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
    /**
     * 医院信息添加
     */
    public function PackageAdd(Request $request)
    {
        try {
            $hospitalAdd = ReservationLogic::hospitalAdd($request);
            return $this->witejson(0,$hospitalAdd,'医院添加成功');
        } catch (\Exception $exception) {
            return $this->witejson(1,'',$exception->getMessage());
        }
    }

    /**
     * 医院信息删除
     */
    public function PackageDel(Request $request)
    {
        try {
            $hospitalId = $request->get('id');
            $hospitalMessage = ReservationLogic::hospitalDel($hospitalId);
            return $this->witejson(0,$hospitalMessage,'医院删除成功');
        } catch (\Exception $exception) {
            return $this->witejson(1,'',$exception->getMessage());
        }
    }

    /**
     * 医院信息查找
     */
    public function PackageSeek(Request $request)
    {
        try {
            $keyword = $request->get('keyword');
            $hospitalMessage = ReservationLogic::hospitalSeek($keyword);
            return $this->witejson(0,$hospitalMessage,'医院查找成功');
        } catch (\Exception $exception) {
            return $this->witejson(1,'',$exception->getMessage());
        }
    }

    /**
     * 医院详情
     */
    public function PackageDetails(Request $request)
    {
        try {
            $fangId = $request->get('id');
            $hospitalMessage = ReservationLogic::hospitalDetails($fangId);
            return $this->witejson(0,$hospitalMessage,'医院详情展示成功');
        } catch (\Exception $exception) {
            return $this->witejson(1,'',$exception->getMessage());
        }
    }

    /**
     * 医院修改
     */
    public function PackageUpdated(Request $request)
    {
        try {
            $SecondaryMessageUpdated = $request->post();
            $hospitalAdd = ReservationLogic::hospitalUpdated($SecondaryMessageUpdated);
            return $this->witejson(0,$hospitalAdd,'医院修改成功');
        } catch (\Exception $exception) {
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
    /**
     * Undocumented function
     *  医院信息存入es
     * @return void
     */
    public function PackageEstateEsCreate(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $realeEstateList=hospitalInformation::get()->toArray();
            $res=ReservationLogic::PackageEstateEsCreate($realeEstateList);
            return $this->witejson(0,$res,'加载成功');
        }catch(\Exception  $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
    /**
     * 医院es搜索
     */
    public function PackageSearch(Request $request)
    {
        try {
            $keyword = $request->get('keyword');
            $hospitalMessage = ReservationLogic::hospitalSearch($keyword);
            return $this->witejson(0,$hospitalMessage,'医院es搜索成功');
        } catch (\Exception $exception) {
            return $this->witejson(1,'',$exception->getMessage());
        }
    }

}
